safely

inline suspend fun <T> safely(noinline onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> T): T

It will run block inside of supervisorScope to avoid problems with catching of exceptions

Priorities of ExceptionHandlers:

Remember, that ExceptionHandler from CoroutineContext.get will be used anyway if it is available. After it will be called onException

See also

Parameters

onException

Will be called when happen exception inside of block. By default will throw exception - this exception will be available for catching